#ifndef RTPPARSE_TRANSPORT_H
#define RTPPARSE_TRANSPORT_H

#include "rtp/RtpPacket.h"
#include "rtp/RtpHeaderExtensionIds.h"
#include "RtpListener.h"
#include "rtp/RateCalculator.h"
#include "rtp/Packet.h"
#include "Consumer.h"
#include "TransportCongestionControlClient.h"

#include <map>
#include <memory>
#include <string>

class Transport {
protected:
    void DataReceived(size_t len) {
        this->recvTransmission.Update(len, DepLibUV::GetTimeMs());
    }
    void ReceiveRtpPacket(Rtp::RtpPacket *packet);
    void ReceiveRtcpPacket(Rtp::Rtcp::Packet *packet);
private:
    virtual void RecvStreamClosed(uint32_t ssrc) = 0;
    void HandleRtcpPacket(Rtp::Rtcp::Packet *packet);
protected:
    Consumer* GetConsumerByMediaSsrc(uint32_t ssrc) const;
    Consumer* GetConsumerByRtxSsrc(uint32_t ssrc) const;

private:
    struct Rtp::RtpHeaderExtensionIds recvRtpHeaderExtensionIds;
    RtpListener rtpListener;
    Rtp::RateCalculator recvTransmission;
    Rtp::RtpDataCounter recvRtpTransmission;
    Rtp::RtpDataCounter recvRtxTransmission;

    std::shared_ptr<TransportCongestionControlClient> tccClient { nullptr };
    std::shared_ptr<TransportCongestionControlClient> tccServer { nullptr };

    std::map<std::string, Consumer *> mapConsumers;
    std::map<uint32_t, Consumer *> mapSsrcConsumer;
    std::map<uint32_t, Consumer *> mapRtxSsrcConsumer;
};

#endif